package com.xxl.job.executor.service.jobhandler;


import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;


/**
 * 任务Handler示例（Bean模式）
 * <p>
 * 开发步骤：
 * 1、继承"IJobHandler"：“com.xxl.job.core.handler.IJobHandler”；
 * 2、注册到Spring容器：添加“@Component”注解，被Spring容器扫描为Bean实例；
 * 3、注册到执行器工厂：添加“@JobHandler(value="自定义jobhandler名称")”注解，注解value值对应的是调度中心新建任务的JobHandler属性的值。
 * 4、执行日志：需要通过 "XxlJobLogger.log" 打印执行日志；
 *
 * @author xuxueli 2015-12-19 19:43:36
 */
@JobHandler(value = "testJobhandler")
@Component
@RestController
public class TestJobHandler extends IJobHandler {

    @Override
    public ReturnT<String> execute(String param) throws Exception {
        Map<String,String> paraMap = new HashMap<>();
        paraMap.put("jsonArray","[" +
                "    {" +
                "        \"code\": \"117644789220122624\"," +
                "        \"createTime\": 1530524972000," +
                "        \"factoryCode\": \"888888\"," +
                "        \"factorySN\": \"f0002\"," +
                "        \"id\": 2," +
                "        \"jobnumber\": \"j0001\"," +
                "        \"repairFeedbacks\": []," +
                "        \"sampleCode\": \"117798927006629888\"," +
                "        \"sn\": \"285E4F864C1D40C09700\"," +
                "        \"staffCode\": \"117715226683842560\"," +
                "        \"state\": \"TestSuccess\"," +
                "        \"syncState\": \"Sync\"," +
                "        \"updateTime\": 1530524972000" +
                "    }" +
                "]");
        String result = HttpServer.httpCall("http://localhost:8762/testUnit/synDataFromDown",  paraMap, "POST");
        XxlJobLogger.log("-------------------调度测试结束------------------ "+result);
        return SUCCESS;
    }



}
